package world.snowcrystal.nova.scoring;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import world.snowcrystal.nova.model.entity.App;
import world.snowcrystal.nova.model.entity.UserAnswer;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Component
public class ScoringStrategyContext {

    @Resource
    private List<ScoringStrategy> scoringStrategies;


    public UserAnswer score(List<String> choices, App app) {

        for (ScoringStrategy strategy : scoringStrategies) {
            if (strategy.isSupport(app)) {
                try {
                    return strategy.score(choices, app);
                } catch (Exception e) {
                    log.error("Error while scoring with {} : {}", strategy.getClass().getName(), e.getMessage());
                }
            }
        }
        return null;
    }


}
